package com.gary.mongo.service;

import com.gary.mongo.dao.CommentDAO;
import com.gary.mongo.po.Comment;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * @author peng_rui
 * @date 2022/6/1
 */
@Service
public class CommentService {
    @Resource
    private CommentDAO commentDAO;

    /**
     * save
     * @param comment
     */
    public void saveComment(Comment comment) {
        commentDAO.save(comment);
    }

    /**
     * findAll
     * @return
     */
    public List<Comment> find() {
        return commentDAO.findAll();
    }

    /**
     * del
     * @param id
     */
    public void delete(String id) {
        commentDAO.deleteById(id);
    }

    /**
     * findById
     * @param id
     * @return
     */
    public Comment findById(String id) {
        Optional<Comment> byId = commentDAO.findById(id);
        return byId.get();
    }
}
